From 186f6c4d5eac0545267310ce2ccd13553d230001 Mon Sep 17 00:00:00 2001 From: Jens Frank Date: Sat, 2 Oct 2004 19:49:54 +0000 Subject: [PATCH] Moved 'get previous/next revision' code from DifferenceEngine to Title' --- includes/DifferenceEngine.php | 23 +++++++++++++---------- includes/Title.php | 29 +++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 10 deletions(-) diff --git a/includes/DifferenceEngine.php b/includes/DifferenceEngine.php index 198c9b3931..9276d0f058 100644 --- a/includes/DifferenceEngine.php +++ b/includes/DifferenceEngine.php @@ -25,11 +25,13 @@ class DifferenceEngine { # Get previous one from DB. # $this->mNewid = intval($old); - $dbr =& wfGetDB( DB_SLAVE ); - $this->mOldid = $dbr->selectField( 'old', 'old_id', - "old_title='" . $wgTitle->getDBkey() . "'" . - ' AND old_namespace=' . $wgTitle->getNamespace() . - " AND old_id<{$this->mNewid} ORDER BY old_id DESC" ); + + $this->mOldid = $wgTitle->getPreviousRevisionID( $this->mNewid ); + #$dbr =& wfGetDB( DB_SLAVE ); + #$this->mOldid = $dbr->selectField( 'old', 'old_id', + #"old_title='" . $wgTitle->getDBkey() . "'" . + #' AND old_namespace=' . $wgTitle->getNamespace() . + #" AND old_id<{$this->mNewid} ORDER BY old_id DESC" ); } elseif ( 'next' == $new ) { @@ -37,11 +39,12 @@ class DifferenceEngine { # Get previous one from DB. # $this->mOldid = intval($old); - $dbr =& wfGetDB( DB_SLAVE ); - $this->mNewid = $dbr->selectField( 'old', 'old_id', - "old_title='" . $wgTitle->getDBkey() . "'" . - ' AND old_namespace=' . $wgTitle->getNamespace() . - " AND old_id>{$this->mOldid} ORDER BY old_id " ); + $this->mNewid = $wgTitle->getNextRevisionID( $this->mOldid ); + #$dbr =& wfGetDB( DB_SLAVE ); + #$this->mNewid = $dbr->selectField( 'old', 'old_id', + # "old_title='" . $wgTitle->getDBkey() . "'" . + # ' AND old_namespace=' . $wgTitle->getNamespace() . + # " AND old_id>{$this->mOldid} ORDER BY old_id " ); if ( false === $this->mNewid ) { # if no result, NewId points to the newest old revision. The only newer # revision is cur, which is "0". diff --git a/includes/Title.php b/includes/Title.php index 94da807b41..4adec439e2 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -1698,5 +1698,34 @@ class Title { function oldCond() { return array( 'old_namespace' => $this->mNamespace, 'old_title' => $this->mDbkeyform ); } + + /** + * Get the revision ID of the previous revision + * + * @param integer $revision Revision ID. Get the revision that was before this one. + * @return interger $oldrevision|false + */ + function getPreviousRevisionID( $revision ) { + $dbr =& wfGetDB( DB_SLAVE ); + return $dbr->selectField( 'old', 'old_id', + "old_title='" . $this->getDBkey() . "'" . + ' AND old_namespace=' . $this->getNamespace() . + " AND old_id<{$revision} ORDER BY old_id DESC" ); + } + + /** + * Get the revision ID of the next revision + * + * @param integer $revision Revision ID. Get the revision that was after this one. + * @return interger $oldrevision|false + */ + function getNextRevisionID( $revision ) { + $dbr =& wfGetDB( DB_SLAVE ); + return $dbr->selectField( 'old', 'old_id', + "old_title='" . $this->getDBkey() . "'" . + ' AND old_namespace=' . $this->getNamespace() . + " AND old_id>{$revision} ORDER BY old_id" ); + } + } ?> -- 2.20.1